# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python
import shutil
from cerbero.utils import shell

class Recipe(recipe.Recipe):
    name = 'moltenvk-tools'
    version = '1.1.101.0'
    licenses = [License.Apachev2]
    stype = SourceType.TARBALL
    tarball_dirname = "vulkansdk-macos-%(version)s"
    # Mirrored because lunarg.com has an extremely small download limit
    # url = 'https://sdk.lunarg.com/sdk/download/%(version)s/mac/' + tarball_dirname + '.tar.gz'
    url = 'https://gstreamer.freedesktop.org/data/src/mirror/' + tarball_dirname + '.tar.gz'
    tarball_checksum = 'b175849a1c609b561ef2406ced3f2e408af2970725a45f49547d03cefd5bbc39'
    btype = BuildType.CUSTOM

    files_bins = [
        'glslangValidator',
        'glslc',
        'spirv-as',
        'spirv-cfg',
        'spirv-cross',
        'spirv-dis',
        'spirv-link',
        'spirv-opt',
        'spirv-reduce',
        'spirv-remap',
        'spirv-stats',
        'spirv-val',
    ]

    def prepare(self):
        if self.config.target_platform not in (Platform.IOS, Platform.DARWIN):
            raise InvalidRecipeError(self, "Invalid platform")

    def install(self):
        srcdir = self.config.moltenvk_prefix
        prefix = self.config.prefix

        if os.path.exists(srcdir):
            shutil.rmtree(srcdir)
        shell.copy_dir(self.build_dir, srcdir)

        for bin in self.files_bins:
            shutil.copy(os.path.join(srcdir, 'macOS', 'bin', bin), os.path.join(prefix, 'bin', bin))
